package com.cadre.system.service.impl;

import com.alibaba.fastjson.JSON;
import com.cadre.common.utils.oldutil.ResultEnum;
import com.cadre.common.exception.CadreException;
import com.cadre.common.utils.SecurityUtils;
import com.cadre.common.utils.oldutil.*;
import com.cadre.system.domain.officer.A04;
import com.cadre.system.domain.officer.A17;
import com.cadre.system.mapper.A04Mapper;
import com.cadre.system.mapper.A17Mapper;
import com.cadre.system.mapper.AppointRemoveMapper;
import com.cadre.system.olddomain.XMLUtils;
import com.cadre.system.service.AppointRemoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.sql.Blob;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class AppointRemoveServiceImpl implements AppointRemoveService {
    @Autowired
    AppointRemoveMapper appointRemoveMapper;
    @Autowired
    ReportConfig reportConfig;
    @Autowired
    DocBatchPrint docBatchPrint;
    @Autowired
    A04Mapper a04Mapper;
    @Resource
    private A17Mapper a17Mapper;

    @Override
    public ResultVO listPerson(String[] personIds) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> list = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            Map<String, Object> a19 = this.appointRemoveMapper.selectPerson(personIds[i]);
            if (CollectionUtils.isEmpty(a19)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            Object a1701 = a19.get("a1701");
            if (a1701 != null) {
                if (a1701 instanceof byte[]) {
                    byte[] bytes = (byte[]) a1701;
                    a19.put("a0171_a", bytes);
                } else if (a1701 instanceof Blob) {
                    Blob b = (Blob) a1701;
                    try {
                        a19.put("a0171_a", b.getBytes(1, (int) b.length()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    // 处理其他可能的类型
                    throw new IllegalArgumentException("Unsupported type for 'a1701': " + a1701.getClass().getName());
                }
                a19.remove("a1701");
            } else {
                a19.remove("a1701");
            }
            a19.put("a01_a0184a", a19.get("a01_a0184a") == null ? "" : a19.get("a01_a0184a").toString());
            if (a19.get("a01_a0111") != null && (a19.get("a01_a0111").toString().startsWith("内蒙古") || a19.get("a01_a0111").toString().startsWith("黑龙江"))) {
                String jiguan = a19.get("a01_a0111").toString();
                a19.put("a01_a0111", jiguan.substring(0, 3) + "\n" + jiguan.substring(3, jiguan.length()));
            }
            if (a19.get("a2601") != null && a19.get("a2701") != null) {
                a19.put("a01_a1421", a19.get("a2601").toString() + "\r\n" + a19.get("a2701").toString());
            } else if (a19.get("a2601") != null) {
                a19.put("a01_a1421", a19.get("a2601").toString());
            } else if (a19.get("a2701") != null) {
                a19.put("a01_a1421", a19.get("a2701").toString());
            } else {
                a19.put("a01_a1421", "");
            }
            a19.remove("a2601");
            a19.remove("a2701");
            if (a19.get("a01_a0107_time") != null) {
                a19.put("AGE", Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(a19.get("a01_a0107_time")))));
            } else {
                a19.put("AGE", "");
            }
            List<Map<String, Object>> listrelatives = this.appointRemoveMapper.selectFamilyByID(personIds[i]);
            for (Map<String, Object> relatives : listrelatives) {
                if (relatives.get("A7914") != null) {
                    String zhengzhimianmao = relatives.get("A7914") == null ? "" : relatives.get("A7914").toString();
                    String finstr = zhengzhimianmao;
                    if (zhengzhimianmao.length() == 4) {
                        finstr = zhengzhimianmao.substring(0, 2) + "\n" + zhengzhimianmao.substring(2, 4);
                    }
                    relatives.put("A7914", finstr);
                }
                if (relatives.get("A7922") == null) {
                    relatives.put("A79_AGE", "");
                } else if (relatives.get("A7923") == null) {
                    relatives.put("A79_AGE", Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(relatives.get("A7922")))));
                } else if (String.valueOf(relatives.get("A7923")).contains("去世") || String.valueOf(relatives.get("A7923")).contains("已故") || String.valueOf(relatives.get("A7923")).contains("死亡")) {
                    relatives.put("A79_AGE", "");
                } else {
                    relatives.put("A79_AGE", Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(relatives.get("A7922")))));
                }
            }
            a19.put("relatives", listrelatives);
            try {
                a19.put("jiandatainfo", new JianLiFormat().processJianLi(String.valueOf(a19.get("a01_a1701"))));
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            List<A17> a17list = this.a17Mapper.select3YearByPerson(a19.get("oid").toString());
            String a17 = "";
            if (a17list.size() > 0) {
                a17list.stream().sorted(Comparator.comparing((A17 v0) -> {
                    return v0.getA1701();
                }).reversed()).collect(Collectors.toList());
                for (A17 a17s : a17list) {
                    a17 = a17 + a17s.getA1701() + "年度" + a17s.getA1704() + a17s.getA1702() + a17s.getA1703() + "\n";
                }
            }
            a19.put("a17", a17);
            Map<String, Object> a04map = new HashMap<>();
            a04map.put("personid", personIds[i]);
            a04map.put("isout", 1);
            a04map.put("A0449", "1");
            Map<String, String> quanrixueli = xueli(this.a04Mapper.selectByPersonid(a04map));
            if (quanrixueli.get("xueli") != null && !quanrixueli.get("xueli").equals("")) {
                String[] xuelis = quanrixueli.get("xueli").split("\n");
                a19.put("a01_a0902", xuelis[0]);
                if (xuelis.length > 1) {
                    a19.put("a01_a0905", xuelis[1]);
                }
            }
            a19.put("a01_a0814", quanrixueli.get("yuanxiao"));
            a04map.put("A0449", "2");
            Map<String, String> zaizhixueli = xueli(this.a04Mapper.selectByPersonid(a04map));
            if (zaizhixueli.get("xueli") != null && !zaizhixueli.get("xueli").equals("")) {
                String[] xuelis2 = zaizhixueli.get("xueli").split("\n");
                a19.put("a01_a0801", xuelis2[0]);
                if (xuelis2.length > 1) {
                    a19.put("a01_a0901", xuelis2[1]);
                }
            }
            a19.put("a01_a0903", zaizhixueli.get("yuanxiao"));
            list.add(a19);
        }
        return ResultVOUtil.success(list);
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void exportWord(String[] personIds, HttpServletResponse response) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            new HashMap();
            Map<String, Object> map = this.appointRemoveMapper.selectPersonByID(personIds[i]);
            if (CollectionUtils.isEmpty(map)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            map.put("a01_a0184a", map.get("a01_a0184a") == null ? "" : map.get("a01_a0184a").toString());
            if (map.get("a01_a0111") != null && (map.get("a01_a0111").toString().startsWith("内蒙古") || map.get("a01_a0111").toString().startsWith("黑龙江"))) {
                String jiguan = map.get("a01_a0111").toString();
                map.put("a01_a0111", jiguan.substring(0, 3) + "\n" + jiguan.substring(3, jiguan.length()));
            }
            if (map.get("a2601") == null || map.get("a2601").equals("")) {
                map.put("a01_a1421", "");
            } else {
                map.put("a01_a1421", map.get("a2601").toString());
            }
            map.remove("a2601");
            map.remove("a2701");
            Object a1701 = map.get("a1701");
            if (a1701 != null) {
                if (a1701 instanceof byte[]) {
                    byte[] bytes = (byte[]) a1701;
                    map.put("a0171_a", bytes);
                } else if (a1701 instanceof Blob) {
                    Blob b = (Blob) a1701;
                    try {
                        map.put("a0171_a", b.getBytes(1, (int) b.length()));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    // 处理其他可能的类型
                    throw new IllegalArgumentException("Unsupported type for 'a1701': " + a1701.getClass().getName());
                }
                map.remove("a1701");
            } else {
                map.remove("a1701");
            }
            try {
                if (map.get("a01_a0107_time") != null) {
                    map.put("a01_age", "(" + AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(map.get("a01_a0107_time"))) + "岁)");
                    map.put("a01_a0107_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0107_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0134_time") != null) {
                    map.put("a01_a0134_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0134_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0141") != null) {
                    map.put("a01_a0141", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0141").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            List<Map<String, Object>> resume = this.appointRemoveMapper.selectFamilyByID(personIds[i]);
            for (Map s : resume) {
                map.put("new200" + resume.indexOf(s), s.get("A7910"));
                map.put("new201" + resume.indexOf(s), s.get("A7921"));
                String zhengzhimianmao = s.get("A7914") == null ? "" : s.get("A7914").toString();
                String finstr = zhengzhimianmao;
                if (zhengzhimianmao.length() == 4) {
                    finstr = zhengzhimianmao.substring(0, 2) + "\n" + zhengzhimianmao.substring(2, 4);
                }
                map.put("new202" + resume.indexOf(s), finstr);
                map.put("new203" + resume.indexOf(s), s.get("A7923"));
                if (!(s.get("A7923") == null || s.get("A7922") == null || s.get("A7923").toString().contains("去世"))) {
                    map.put("compute_" + (resume.indexOf(s) + 1), Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(s.get("A7922")))));
                }
            }
            mapList.add(map);
        }
        if (mapList.size() == 1) {
            WordUtils.downloadWord(mapList, this.reportConfig.getWorldTmp(), response);
        } else {
            WordUtils.downloadWord(mapList, this.reportConfig.getWorldTmp(), this.reportConfig.getFile(), response);
        }
    }

    public static Map<String, String> xueli(List<A04> a04List) {
        int yuanxiaotype;
        int xueweitype;
        Map<String, String> map = new HashMap<>();
        String xueli = "";
        String yuanxiao = "";
        if (a04List != null && a04List.size() > 0) {
            for (A04 a04 : a04List) {
                String a0463 = a04.getA0463();
                String a04632 = a0463 == null ? "9999" : a0463;
                a04.setA0463(a04632);
                if (a04.getA0460() == null) {
                    String a0463s = a04632.length() == 1 ? a04632 : String.valueOf(a04632.charAt(0));
                    if (a0463s.equals("2") || a0463s.equals("3")) {
                        a04.setA0460("11");
                    } else {
                        a04.setA0460("9999");
                    }
                }
            }
            List<A04> a04List2 =  a04List.stream().sorted(Comparator.comparing((A04 v0) -> {
                return v0.getA0460();
            }).thenComparing((v0) -> {
                return v0.getA0463();
            })).collect(Collectors.toList());
            if (a04List2.size() == 1) {
                xueli = a04List2.get(0).getA0405() + "\n" + a04List2.get(0).getA0440();
                yuanxiao = a04List2.get(0).getA0435() + a04List2.get(0).getA0467() + a04List2.get(0).getA0411();
            } else {
                A04 a04_1 = a04List2.get(0);
                A04 a04_2 = a04List2.get(1);
                String a0460_1 = a04_1.getA0460();
                String a0460_2 = a04_2.getA0460();
                if (!a0460_1.equals("9999") && !a0460_2.equals("9999")) {
                    String a0460_12 = a0460_1.substring(0, 1);
                    String a0460_22 = a0460_2.substring(0, 1);
                    Integer integer1 = Integer.valueOf(a0460_12);
                    Integer integer2 = Integer.valueOf(a0460_22);
                    if (integer1.intValue() > integer2.intValue()) {
                        xueli = a04_2.getA0405();
                        yuanxiaotype = 2;
                    } else if (integer1.intValue() < integer2.intValue()) {
                        xueli = a04_1.getA0405();
                        if (xueli == null) {
                            xueli = a04_2.getA0405();
                            yuanxiaotype = 2;
                        } else {
                            yuanxiaotype = 1;
                        }
                    } else {
                        xueli = a04_1.getA0405();
                        if (xueli == null) {
                            xueli = a04_2.getA0405();
                            yuanxiaotype = 2;
                        } else {
                            yuanxiaotype = 1;
                        }
                    }
                } else if (!a0460_1.equals("9999")) {
                    xueli = a04_1.getA0405();
                    yuanxiaotype = 1;
                } else {
                    xueli = a04_2.getA0405();
                    yuanxiaotype = 2;
                }
                String a0463_1 = a04_1.getA0463();
                String a0463_2 = a04_2.getA0463();
                String a0463_12 = a0463_1.equals("0") ? "9999" : a0463_1;
                String a0463_22 = a0463_2.equals("0") ? "9999" : a0463_2;
                if (!a0463_12.equals("9999") && !a0463_22.equals("9999")) {
                    a0463_12 = a0463_12.substring(0, 1);
                    a0463_22 = a0463_22.substring(0, 1);
                    Integer integer12 = Integer.valueOf(a0463_12);
                    Integer integer22 = Integer.valueOf(a0463_22);
                    if (integer12.intValue() > integer22.intValue()) {
                        xueli = xueli + "\n" + a04_2.getA0440();
                        xueweitype = 2;
                    } else if (integer12.intValue() < integer22.intValue()) {
                        xueli = xueli + "\n" + a04_1.getA0440();
                        xueweitype = 1;
                    } else {
                        xueli = xueli + "\n" + a04_1.getA0440() + "," + a04_2.getA0440();
                        xueweitype = 3;
                    }
                } else if (a0463_12.equals("9999") && a0463_22.equals("9999")) {
                    xueweitype = 3;
                } else if (!a0463_12.equals("9999")) {
                    xueli = xueli + "\n" + a04_1.getA0440();
                    xueweitype = 1;
                } else {
                    xueli = xueli + "\n" + a04_2.getA0440();
                    xueweitype = 2;
                }
                String xueliyuanxiao = null;
                if (yuanxiaotype == 1) {
                    xueliyuanxiao = a04_1.getA0435() + a04_1.getA0467() + a04_1.getA0411();
                }
                if (yuanxiaotype == 2) {
                    xueliyuanxiao = a04_2.getA0435() + a04_2.getA0467() + a04_2.getA0411();
                }
                String xueweiyuanxiao = null;
                if (xueweitype == 1) {
                    xueweiyuanxiao = a04_1.getA0435() + a04_1.getA0467() + a04_1.getA0411();
                }
                if (xueweitype == 2) {
                    xueweiyuanxiao = a04_2.getA0435() + a04_2.getA0467() + a04_2.getA0411();
                }
                if (xueliyuanxiao.equals(xueweiyuanxiao)) {
                    yuanxiao = xueliyuanxiao;
                } else {
                    yuanxiao = xueliyuanxiao + "\n" + xueweiyuanxiao;
                }
                if (xueweitype == 3) {
                    if (a0463_12.equals("9999") && a0463_22.equals("9999")) {
                        xueli = a04_1.getA0405() + "," + a04_2.getA0405() + "\n" + a04_1.getA0440() + " " + a04_2.getA0440();
                    }
                    yuanxiao = a04_1.getA0435() + a04_1.getA0467() + a04_1.getA0411() + "\n" + a04_2.getA0435() + a04_2.getA0467() + a04_2.getA0411();
                }
            }
        }
        String xueli2 = xueli.replace("null", "");
        String yuanxiao2 = yuanxiao.replace("null", "");
        map.put("xueli", xueli2);
        map.put("yuanxiao", yuanxiao2);
        return map;
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void printWord(String[] personIds, HttpServletResponse response) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            new HashMap();
            Map<String, Object> map = this.appointRemoveMapper.selectPersonByID(personIds[i]);
            if (CollectionUtils.isEmpty(map)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            map.put("a01_a0184a", map.get("a01_a0184a") == null ? "" : map.get("a01_a0184a").toString());
            if (map.get("a01_a0111") != null && (map.get("a01_a0111").toString().startsWith("内蒙古") || map.get("a01_a0111").toString().startsWith("黑龙江"))) {
                String jiguan = map.get("a01_a0111").toString();
                map.put("a01_a0111", jiguan.substring(0, 3) + "\n" + jiguan.substring(3, jiguan.length()));
            }
            if (map.get("a2601") == null || map.get("a2601").equals("")) {
                map.put("a01_a1421", "");
            } else {
                map.put("a01_a1421", map.get("a2601").toString());
            }
            map.remove("a2601");
            map.remove("a2701");
            if (map.get("a1701") != null) {
                Blob blob = (Blob) map.get("a1701");
                map.put("a0171_a", map.get("a1701"));
                map.remove("a1701");
            } else {
                map.remove("a1701");
            }
            try {
                if (map.get("a01_a0107_time") != null) {
                    map.put("a01_age", "(" + AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(map.get("a01_a0107_time"))) + "岁)");
                    map.put("a01_a0107_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0107_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0134_time") != null) {
                    map.put("a01_a0134_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0134_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0141") != null) {
                    map.put("a01_a0141", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0141").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            List<Map<String, Object>> resume = this.appointRemoveMapper.selectFamilyByID(personIds[i]);
            for (Map s : resume) {
                if (s != null) {
                    map.put("new200" + resume.indexOf(s), s.get("A7910"));
                    map.put("new201" + resume.indexOf(s), s.get("A7921"));
                    String zhengzhimianmao = s.get("A7914") == null ? "" : s.get("A7914").toString();
                    String finstr = zhengzhimianmao;
                    if (zhengzhimianmao.length() == 4) {
                        finstr = zhengzhimianmao.substring(0, 2) + "\n" + zhengzhimianmao.substring(2, 4);
                    }
                    map.put("new202" + resume.indexOf(s), finstr);
                    map.put("new203" + resume.indexOf(s), s.get("A7923"));
                    if (!(s.get("A7923") == null || s.get("A7922") == null || s.get("A7923").toString().contains("去世"))) {
                        map.put("compute_" + (resume.indexOf(s) + 1), Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(s.get("A7922")))));
                    }
                }
            }
            mapList.add(map);
        }
        WordUtils.mergeWord(mapList, this.reportConfig, response);
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void exportLrmx(String[] personIds, HttpServletResponse response) {
        File file;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            new HashMap();
            Map<String, Object> map = this.appointRemoveMapper.selectPersonByID(personIds[i]);
            if (CollectionUtils.isEmpty(map)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            if (map.get("a1701") != null) {
                try {
                    map.put("a0171_a", map.get("a1701"));
                    map.remove("a1701");
                } catch (Exception e) {
                    e.printStackTrace();
                }
                map.remove("a1701");
            } else {
                map.remove("a1701");
            }
            if (map.get("a2601") != null && map.get("a2701") != null) {
                map.put("a01_a1421", map.get("a2601").toString() + "\r\n" + map.get("a2701").toString());
            } else if (map.get("a2601") != null) {
                map.put("a01_a1421", map.get("a2601").toString());
            } else if (map.get("a2701") != null) {
                map.put("a01_a1421", map.get("a2701").toString());
            } else {
                map.put("a01_a1421", "");
            }
            map.remove("a2601");
            map.remove("a2701");
            if (map.get("a01_a0814") != null) {
                try {
                    String[] temps = map.get("a01_a0814").toString().split(" ");
                    map.put("a01_a0814", temps[0]);
                    map.put("a01_a0814_1", temps[1]);
                } catch (Exception e2) {
                    map.put("a01_a0814_1", "");
                }
            }
            if (map.get("a01_a0903") != null) {
                try {
                    String[] temps2 = map.get("a01_a0903").toString().split(" ");
                    map.put("a01_a0903", temps2[0]);
                    map.put("a01_a0903_1", temps2[1]);
                } catch (Exception e3) {
                    map.put("a01_a0903_1", "");
                }
            }
            if (map.get("a01_a0107_time") != null) {
                map.put("a01_age", Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(map.get("a01_a0107_time")))));
            }
            try {
                if (map.get("a01_a0107_time") != null) {
                    map.put("a01_a0107_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0107_time").toString()), "yyyyMM"));
                }
                if (map.get("a01_a0134_time") != null) {
                    map.put("a01_a0134_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0134_time").toString()), "yyyyMM"));
                }
                if (map.get("a01_a0141") != null) {
                    map.put("a01_a0141", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0141").toString()), "yyyyMM"));
                }
            } catch (ParseException e4) {
                e4.printStackTrace();
            }
            map.put("familyinfo", this.appointRemoveMapper.selectFamilyByID(personIds[i]));
            map.put("a01_rmb7", SecurityUtils.getLoginUser().getUsername());
            mapList.add(map);
        }
        if (mapList.size() == 1) {
            file = XMLUtils.setLrmxFileByA01(mapList, false);
        } else {
            file = XMLUtils.setLrmxFileByA01(mapList, true);
        }
        try {
            System.out.println("=====>fileName:" + file.getName());
        } catch (Exception e5) {
        }
        WordUtils.toDownloadLrMx(file, response);
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public List<Map<String, Object>> selectPersonByUnitID(String unitid) {
        return this.appointRemoveMapper.selectPersonByUnitID(unitid);
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void batchPrintWord(String[] personIds, HttpServletResponse response) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            new HashMap();
            Map<String, Object> map = this.appointRemoveMapper.selectPersonByID(personIds[i]);
            if (CollectionUtils.isEmpty(map)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            map.put("a01_a0184a", map.get("a01_a0184a") == null ? "" : map.get("a01_a0184a").toString());
            if (map.get("a01_a0111") != null && (map.get("a01_a0111").toString().startsWith("内蒙古") || map.get("a01_a0111").toString().startsWith("黑龙江"))) {
                String jiguan = map.get("a01_a0111").toString();
                map.put("a01_a0111", jiguan.substring(0, 3) + "\n" + jiguan.substring(3, jiguan.length()));
            }
            if (map.get("a2601") == null || map.get("a2601").equals("")) {
                map.put("a01_a1421", "");
            } else {
                map.put("a01_a1421", map.get("a2601").toString());
            }
            map.remove("a2601");
            map.remove("a2701");
            if (map.get("a1701") != null) {
                Blob blob = (Blob) map.get("a1701");
                map.put("a0171_a", map.get("a1701"));
                map.remove("a1701");
            } else {
                map.remove("a1701");
            }
            try {
                if (map.get("a01_a0107_time") != null) {
                    map.put("a01_age", "(" + AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(map.get("a01_a0107_time"))) + "岁)");
                    map.put("a01_a0107_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0107_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0134_time") != null) {
                    map.put("a01_a0134_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0134_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0141") != null) {
                    map.put("a01_a0141", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0141").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            List<Map<String, Object>> resume = this.appointRemoveMapper.selectFamilyByID(personIds[i]);
            for (Map s : resume) {
                if (s != null) {
                    map.put("new200" + resume.indexOf(s), s.get("A7910"));
                    map.put("new201" + resume.indexOf(s), s.get("A7921"));
                    String zhengzhimianmao = s.get("A7914") == null ? "" : s.get("A7914").toString();
                    String finstr = zhengzhimianmao;
                    if (zhengzhimianmao.length() == 4) {
                        finstr = zhengzhimianmao.substring(0, 2) + "\n" + zhengzhimianmao.substring(2, 4);
                    }
                    map.put("new202" + resume.indexOf(s), finstr);
                    map.put("new203" + resume.indexOf(s), s.get("A7923"));
                    if (!(s.get("A7923") == null || s.get("A7922") == null || s.get("A7923").toString().contains("去世"))) {
                        map.put("compute_" + (resume.indexOf(s) + 1), Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(s.get("A7922")))));
                    }
                }
            }
            mapList.add(map);
        }
        this.docBatchPrint.printWord(mapList, this.reportConfig, response);
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void batchDownWord(String[] personIds, HttpServletResponse response) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM";
        List<Map<String, Object>> mapList = new ArrayList<>();
        for (int i = 0; i < personIds.length; i++) {
            new HashMap();
            Map<String, Object> map = this.appointRemoveMapper.selectPersonByID(personIds[i]);
            if (CollectionUtils.isEmpty(map)) {
                throw new CadreException(ResultEnum.PARAMETER_ERROR);
            }
            map.put("a01_a0184a", map.get("a01_a0184a") == null ? "" : map.get("a01_a0184a").toString());
            if (map.get("a01_a0111") != null && (map.get("a01_a0111").toString().startsWith("内蒙古") || map.get("a01_a0111").toString().startsWith("黑龙江"))) {
                String jiguan = map.get("a01_a0111").toString();
                map.put("a01_a0111", jiguan.substring(0, 3) + "\n" + jiguan.substring(3, jiguan.length()));
            }
            if (map.get("a2601") == null || map.get("a2601").equals("")) {
                map.put("a01_a1421", "");
            } else {
                map.put("a01_a1421", map.get("a2601").toString());
            }
            map.remove("a2601");
            map.remove("a2701");
            if (map.get("a1701") != null) {
                Blob blob = (Blob) map.get("a1701");
                map.put("a0171_a", map.get("a1701"));
                map.remove("a1701");
            } else {
                map.remove("a1701");
            }
            try {
                if (map.get("a01_a0107_time") != null) {
                    map.put("a01_age", "(" + AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(map.get("a01_a0107_time"))) + "岁)");
                    map.put("a01_a0107_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0107_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0134_time") != null) {
                    map.put("a01_a0134_time", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0134_time").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
                if (map.get("a01_a0141") != null) {
                    map.put("a01_a0141", DateUtil.dateToString(simpleDateFormat.parse(map.get("a01_a0141").toString()), DateUtil.MONTG_DATE_FORMAT));
                }
            } catch (ParseException e) {
                e.printStackTrace();
            }
            List<Map<String, Object>> resume = this.appointRemoveMapper.selectFamilyByID(personIds[i]);
            for (Map s : resume) {
                if (s != null) {
                    map.put("new200" + resume.indexOf(s), s.get("A7910"));
                    map.put("new201" + resume.indexOf(s), s.get("A7921"));
                    String zhengzhimianmao = s.get("A7914") == null ? "" : s.get("A7914").toString();
                    String finstr = zhengzhimianmao;
                    if (zhengzhimianmao.length() == 4) {
                        finstr = zhengzhimianmao.substring(0, 2) + "\n" + zhengzhimianmao.substring(2, 4);
                    }
                    map.put("new202" + resume.indexOf(s), finstr);
                    map.put("new203" + resume.indexOf(s), s.get("A7923"));
                    if (!(s.get("A7923") == null || s.get("A7922") == null || s.get("A7923").toString().contains("去世"))) {
                        map.put("compute_" + (resume.indexOf(s) + 1), Integer.valueOf(AgeUtil.getAgeFromBirthTime(simpleDateFormat.format(s.get("A7922")))));
                    }
                }
            }
            mapList.add(map);
        }
        this.docBatchPrint.downWord(mapList, this.reportConfig, response);
    }

    private String formatRudang(String str) {
        String tim;
        if (str == null || str.equals("")) {
            return "";
        }
        if (StrValidate.isDigit(str) && str.length() == 7) {
            return str;
        }
        if (StrValidate.isDigit(str) && str.length() == 6) {
            return str.substring(0, 4) + "." + str.substring(4, str.length());
        }
        if (StrValidate.isChinese(str)) {
            return "（" + str.replaceAll(";", "、").replaceAll("；", "、") + "）";
        }
        if (!StrValidate.isLetterDigitOrChinese(str)) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        if (str.contains(".")) {
            tim = str.substring(0, 7);
            sb.append(str.substring(8, str.length()).replaceAll(";", "、").replaceAll("；", "、"));
        } else {
            tim = str.substring(0, 4) + "." + str.substring(4, 6);
            sb.append(str.substring(7, str.length()).replaceAll(";", "、").replaceAll("；", "、"));
        }
        sb.append("\n").append("（").append(tim).append("）");
        return sb.toString();
    }

    @Override // com.tdqy.cadre.modular.profess.service.AppointRemoveService
    public void onlinePrintWord(List<Map<String, Object>> map, HttpServletResponse response) {
        new Renmb4word(map, this.reportConfig.getNwordTmp()).setTempValue(response);
    }
}
